package com.treasure.mall.biz.repository.order;

import com.treasure.mall.biz.base.JpaSearchableRepository;
import com.treasure.mall.biz.entity.order.SubOrderPO;
import com.treasure.mall.zbq.common.ienum.order.OrderEnums;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/6/11
 */
@Repository
public interface SubOrderRepository extends JpaSearchableRepository<SubOrderPO, String> {
    List<SubOrderPO> findByOrderPO_OrderId(String orderId);

    List<SubOrderPO> findByOrderPO_PayStatus(OrderEnums.PayStatus payStatus);

    @Query("update SubOrderPO po set po.amountDone=true where id=?1")
    @Modifying
    @Transactional
    int amountDone(String orderId);

    @Query("select count(po) from SubOrderPO po where po.orderPO.payStatus=?1 " +
            "and po.orderPO.userPO.userId=?2 " +
            "and po.orderType=?3 and po.liveSessionId is not null")
    long auctionCount(OrderEnums.PayStatus payStatus, Long userId, OrderEnums.OrderType orderType);
}
